package com.onlyphoto.onlymall.mvp.view.activity

import android.view.View
import com.onlyphoto.onlymall.MyApplication
import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.base.BaseActivity
import com.onlyphoto.onlymall.bean.request.PwdBean
import com.onlyphoto.onlymall.listeners.NoDoubleClickListener
import com.onlyphoto.onlymall.mvp.contract.CUpdatePwd
import com.onlyphoto.onlymall.mvp.presenter.PUpdatePwdImpl
import com.onlyphoto.onlymall.utils.AndroidUtils
import com.onlyphoto.onlymall.utils.SharePreferenceUtil
import com.onlyphoto.onlymall.utils.ToastUtil
import kotlinx.android.synthetic.main.activity_updatepwd.*
import kotlinx.android.synthetic.main.activity_updatepwd.back


class UpdatePwdActivity : BaseActivity<PUpdatePwdImpl>(), CUpdatePwd.IVUpdatePwd {

    override fun retry() {}

    override fun init() {

    }

    override fun initListener() {
        AndroidUtils.isButtonEnable(intArrayOf(6, 6, 6), update, old_pwd, new_pwd, new_pwd_confirm)

        back.setOnClickListener{
            finish()
        }

        update.setOnClickListener(object : NoDoubleClickListener(){
            override fun onNoDoubleClick(view: View?) {
                if (new_pwd.text.toString() != new_pwd_confirm.text.toString()) {
                    showToast("两次新密码输入不一致")
                } else {
                    mPresenter?.updatePwd()
                }
            }

        })
    }

    override fun getUpdatePwdBean(): PwdBean {
        val bean = PwdBean()
        bean.post_type = 2
        bean.old_password = old_pwd.text.toString()
        bean.new_password = new_pwd.text.toString()
        bean.user_token = SharePreferenceUtil.getInstance(MyApplication.app).token
        return bean
    }

    override fun updatePwdSuccess() {
        ToastUtil.showToastInCenter(this, "密码已更新")
        finish()
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun loadData() {
        //加载数据
    }

    override fun isFullScreen(): Boolean {
        //是否沉浸式， 默认非沉浸式
        return false
    }

    public override fun initCustomerStatusManager() {
    }

    override fun setContentViewId(): Int {
        return R.layout.activity_updatepwd
    }

    override fun createPresenter() {
        mPresenter = PUpdatePwdImpl(mContext, this)
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

}
